<template>
	<view>

		<!-- <Head :opacity="opci"></Head> -->

		<view class="index-box">
			<!-- 	<Visit></Visit> -->
			<!-- <Business></Business> -->
			<!-- <Banjian></Banjian> -->
			<!-- <Zonghe></Zonghe> -->
			<!-- <JumpDataCenter></JumpDataCenter> -->
			<view class="container-out">
				<view class="inner-item" @click="showDiv">
					<image src="/static/deviceImg/addNewButton.png" class="inner-img"></image>
					<text class="title">建档</text>
				</view>
				<view class="inner-item" @click="instrumentConnection">
					<image src="/static/deviceImg/deviceContact.png" class="inner-img"></image>
					<text class="title">仪器连接</text>
				</view>
				<view class="inner-item" @click="reTesting">
					<image src="/static/deviceImg/fujian.png" class="inner-img"></image>
					<text class="title">复检</text>
				</view>
				<view class="inner-item" @click="goToTest">
					<image src="/static/deviceImg/jiance.png" class="inner-img"></image>
					<text class="title">检测</text>
				</view>
				<view class="inner-item" @click="sampleTest">
					<image src="/static/deviceImg/choujian.png" class="inner-img"></image>
					<text class="title">抽检</text>
				</view>
				<view class="inner-item" @click="progress">
					<image src="/static/deviceImg/jindu.png" class="inner-img"></image>
					<text class="title">进度</text>
				</view>
			</view>
		</view>
		<view :hidden="selectFlag" class="popup_content">
			<view class="popup_title">选择上传的企业</view>
			<view class="popup_textarea_item">
				<uni-data-select v-model="selectedData" :localdata="enterpriseList"></uni-data-select>
				<view @click="submitSelectedData()" class="buttons">
					<text class="popup_button">确定</text>
				</view>
			</view>
		</view>
		<view class="popup_overlay" :hidden="selectFlag" @click="hideDiv()"></view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from "vue"
	import Head from '@/pages/index2/components/head.vue'
	import {
		loginAutoSocial
	} from "@/api/index.js"
	import {
		handleTop
	} from "@/utils/scroll.js"
	import {
		onPageScroll
	} from "@dcloudio/uni-app"
	import {
		getCode,
		getQueryString
	} from '@/common/sdt.js';
	import {
		getAllFactory
	} from '@/api/deviceTest.js';
	const getAllFactoryData = () => {
		getAllFactory().then(res => {
			//console.log('fffffff', res);
			let tempData = {
				value: "",
				text: ""
			};
			if (res.code == 200) {
				res.data.forEach(item => {
					tempData.value = item.factoryId;
					tempData.text = item.factoryName;
					enterpriseList.value.push(tempData);
				})
			}
		})
	}
	const userInfo = ref({})
	const opci = ref(0)
	const selectFlag = ref(true)
	const selectedData = ref("")
	const enterpriseList = ref([])
	onPageScroll((res) => {
		handleTop(res.scrollTop, opci)
	})
	// userInfo.value = uni.getStorageSync('userInfo') || {};
	// if (!userInfo.value.name) {
	// 	// h5环境
	// 	if (!getQueryString('code')) {
	// 		loginAutoSocial().then(res => {
	// 			if (res.error_code) {
	// 				uni.showToast({
	// 					icon: 'none',
	// 					title: res.error_description
	// 				});
	// 				return;
	// 			}
	// 			try {
	// 				uni.setStorageSync('token', res.access_token);
	// 				uni.setStorageSync('userInfo', res);
	// 				getDeptDetail({
	// 					id: res.dept_id
	// 				}).then(res1 => {
	// 					uni.setStorageSync('userDept', res1.data || {})
	// 				})
	// 				uni.showToast({
	// 					icon: 'none',
	// 					title: `欢迎您，${res.nick_name}${res.post_name}!`
	// 				});
	// 				//  === '处长' ? '局长' : res.post_name

	// 			} catch (e) {
	// 				// error
	// 			}
	// 		})
	// 	} else {
	// 		//山东通
	// 		getCode(function(res) {
	// 			const data = res.data || {};
	// 			if (data.permission && JSON.stringify(data.permission) == '{}') {
	// 				uni.reLaunch({
	// 					url: '/pages/permission/permission'
	// 				});
	// 				return;
	// 			}
	// 			userInfo.value = data;
	// 			uni.setStorageSync('userInfo', data);
	// 		});
	// 	}
	// }
	const showDiv = () => {
		//console.log("打开弹窗");
		selectFlag.value = false
	}
	const hideDiv = () => {
		selectFlag.value = true
	}
	const submitSelectedData = () => {
		//没有选择值时提示选择企业
		console.log("selectedData", selectedData.value);
		if (selectedData.value) {
			selectFlag.value = true;
			uni.setStorageSync('factoryId', selectedData.value);
			uni.navigateTo({
				url: '/pages/putOnRecord/detectionPointList?id=' + selectedData.value
			});

		} else {
			alert("请先选择企业");
			return
		}


	}
	const goToTest = () => {
		console.log("进入检测页面");
		uni.navigateTo({
			url: '/pages/testing/index'
		});
	}
	const instrumentConnection = () => {
		console.log("进入仪器连接页面");
		uni.navigateTo({
			url: '/pages/instrumentConnection/index'
		});
	}
	const reTesting = () => {
		console.log("复检");
		uni.showToast({
			icon: 'none',
			title: '正在建设中...'
		});
	}
	const sampleTest = () => {
		console.log("抽检");
		uni.showToast({
			icon: 'none',
			title: '正在建设中...'
		});
	}
	const progress = () => {
		console.log("进度");
		uni.showToast({
			icon: 'none',
			title: '正在建设中...'
		});

	}
	onMounted(() => {
		//获取可选择的企业列表
		getAllFactoryData();
	})
</script>

<style lang="scss" scoped>
	.index-box {
		background: #F4F6FA;
		border-radius: 10rpx 10rpx 0px 0px;
		position: relative;
		top: -10rpx;
		min-height: 50rpx;
		//padding: 100rpx;

	}

	.container-out {
		width: 750rpx;

		display: flex;

		flex-wrap: wrap;

		justify-content: space-around;
		padding-top: 140rpx;
	}

	.inner-item {
		width: 300rpx;
		height: 300rpx;
		cursor: pointer;
		border-radius: 5%;
		margin-bottom: 60rpx;
		background-color: #ffffff;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.inner-img {
			width: 100rpx;
			height: 100rpx;
		}

		.title {
			margin-top: 20rpx;
			font-size: 40upx;
		}

		//justify-content: center;
	}

	.popup_overlay {
		position: fixed;
		top: 0%;
		left: 0%;
		width: 100%;
		height: 100%;
		background-color: black;
		z-index: 1001;
		-moz-opacity: 0.8;
		opacity: .80;
		filter: alpha(opacity=88);
	}

	.popup_content {
		position: fixed;
		top: 50%;
		left: 50%;
		width: 500rpx;
		height: 600rpx;
		margin-left: -270rpx;
		margin-top: -270rpx;
		border: 10px solid white;
		background-color: white;
		z-index: 1002;
		overflow: auto;
	}

	.popup_title {
		width: 480rpx;
		text-align: center;
		font-size: 32rpx;
	}

	.popup_textarea_item {
		padding-top: 5rpx;
		height: 50rpx;
		width: 440rpx;
		background-color: #F1F1F1;
		margin-top: 20rpx;
		margin-left: 20rpx;
		padding-top: 25rpx;
	}

	.popup_textarea {
		width: 410rpx;
		font-size: 26rpx;
		margin-left: 20rpx;
	}

	.popup_button {
		color: #ffffff;
	}

	.buttons {
		text-align: center;
		font-size: 50rpx;
		margin-top: 350rpx;
		background-color: #455bdf;
		cursor: pointer;
		border-radius: 25px;
	}

	.popup_textarea_item {
		background-color: #ffffff;
	}
</style>